<?php
/**
 * WoBase class file.
 *
 * @author		Magki <magkir@163.com>
 * @copyright	Copyright &copy; 2011 Magki Studio
 * @license		GNU General Public License 2.0
 * @version		$Id: WoBase.php 7 2011-08-16 08:11:57Z magkir@163.com $
 * @package		system
 */
/**
 * Gets the application start timestamp.
 */
defined('WO_BEGIN_TIME') or define('WO_BEGIN_TIME', microtime(true));
/**
 * Defines the application installation path.
 */
defined('WO_PATH') or define('WO_PATH', dirname(__FILE__));

class WoBase
{

	private static $_run;

	public static function run()
	{
		return self::$_run;
	}

	public static function setWebapp($webapp)
	{
		if(self::$_run === null) self::$_run = $webapp;
	}

	public static function creatWebapp($config)
	{
		if(is_string($config)) $config = require $config;
		return new CWebapp($config);
	}

	public static function autoload($className)
	{
		if(strpos($className, '\\') === false){
			include($className . '.php');
		}else{
			$path = str_replace('\\', '/', $className);
			$className = substr($className, strrpos($className, '\\') + 1);
			include($path . '.php');
		}
		return class_exists($className, false) || interface_exists($className, false);
	}

	public static function dump($vars, $label = '', $return = false)
	{
		if(ini_get('html_errors')){
			$content = "<pre>\n";
			if($label != ''){
				$content .= "<strong>{$label} :</strong>\n";
			}
			$content .= htmlspecialchars(print_r($vars, true));
			$content .= "\n</pre>\n";
		}else{
			$content = $label . " :\n" . print_r($vars, true);
		}
		if($return){
			return $content;
		}
		echo $content;
		return null;
	}

}

class Wo extends WoBase
{
	
}

spl_autoload_register(array('WoBase', 'autoload'));
set_include_path(get_include_path() . PATH_SEPARATOR . WO_PATH . PATH_SEPARATOR . WO_PATH . DIRECTORY_SEPARATOR . 'base');
?>